// 一开始不妨将所有零件安装在身体上，然后对于所有 Hi>Bi 的零件做 01 背包（价值为
// $H_i−B_i$)，
//  为了满足头部重量不超过身体重量，将背包容量设置为   $ 1/2 \sum W_i$

#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 10;
const int inf = 1e9 + 10;

int main() {
  int n;
  cin >> n;
  vector<int> w(n), h(n), b(n);
  int sum_w = 0, sb = 0;
  for (int i = 0; i < n; i++) {
    cin >> w[i] >> h[i] >> b[i];
    sum_w += w[i];
    sb += b[i];
  }

  int m = sum_w / 2;
  vector<int> dp(m + 1, -inf);
  dp[0] = 0;
  for (int i = 0; i < n; i++) {
    int del = h[i] - b[i];
    if (del <= 0)
      continue;
    int wt = w[i];
    for (int j = m; j >= wt; j--) {
      dp[j] = max(dp[j], dp[j - wt] + del);
    }
  }
  int ans = 0;
  for (int i = 0; i <= m; i++) {
    if (dp[i] > 0)
      ans = max(ans, dp[i]);
  }

  cout << ans + sb << endl;
  return 0;
}